package com.report.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.report.component.WebMemberCollectComponent;
import com.report.dto.request.WebMemberCollectReq;
import com.report.dto.response.WebMemberCollectRes;
import com.report.dto.response.WebMemberDataImageRes;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 收藏
 * @author summer
 * @date 2024-06-28 23:21
 */
@RestController
@RequestMapping(value = "/webMemberCollect")
@AllArgsConstructor
public class WebMemberCollectController {

    private final WebMemberCollectComponent browseComponent;

    /**
     * 查询收藏 报告 图表
     * @param webMemberCollectReq
     * @return
     */
    @PostMapping(value = "/collectReportData")
    public Result<Page<WebMemberCollectRes>> collectReportData(@RequestBody WebMemberCollectReq webMemberCollectReq){
        webMemberCollectReq.setMemberId(Convert.convert(Integer.class, StpUtil.getLoginId()));
        Page<WebMemberCollectRes> page=browseComponent.getWebMemberCollectRes(webMemberCollectReq);
        return Result.successResult(page);
    }


    /**
     * 查询收藏 报告 图表
     * @param webMemberCollectReq
     * @return
     */
    @PostMapping(value = "/collectImageData")
    public Result<Page<WebMemberDataImageRes>> collectImageData(@RequestBody WebMemberCollectReq webMemberCollectReq){
        webMemberCollectReq.setMemberId(Convert.convert(Integer.class, StpUtil.getLoginId()));
        Page<WebMemberDataImageRes> page=browseComponent.collectImageData(webMemberCollectReq);
        return Result.successResult(page);
    }
    /**
     * 关注收藏
     * @param webMemberCollectReq
     * @return
     */
    @PostMapping(value = "/saveWebMemberCollect")
    public Result<String> saveWebMemberBrowse(@RequestBody WebMemberCollectReq webMemberCollectReq){
        browseComponent.saveWebMemberCollect(webMemberCollectReq);
        return Result.successResult();
    }

    /**
     * 取消收藏
     * @param browseId
     * @return
     */
    @GetMapping(value = "/cancelWebMemberBrowse/{browseId}")
    public Result<String> cancelWebMemberBrowse(@PathVariable Integer browseId){
        browseComponent.cancelWebMemberBrowse(browseId);
        return Result.successResult();
    }






}
